package ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

public class ResultBox extends JPanel implements Runnable
{
	private Dimension panelSize;
	private Point panelLocation;

	private AppWindow window;
	private JLabel resultLabel;
	private JDialog dialog;
	private Point frameLocation;
	
	public ResultBox(AppWindow window) {		
		dialog = new JDialog(window.getParentComponent(), false);
		//this.setModal(false);
		Dimension boxSize = window.getBoxSize();
		panelSize = new Dimension(boxSize.width, boxSize.height-18);
		
		this.resultLabel = new JLabel();
		formatLabel();
		this.resultLabel.setFont(new Font("Tempus Sans ITC", Font.BOLD, 14));
		//this.setFocusable(false);
		//this.setRe
		add(this.resultLabel);
		dialog.setContentPane(this);
		
		setSize(panelSize);
		setBackground(Color.WHITE);
		setBorder(new LineBorder(new Color(0, 0, 139), 2, true));
		
		//this.setModal(false);
		dialog.setSize(panelSize);
		dialog.setUndecorated(true);
		this.window = window;
		dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}

	public ResultBox(AppWindow window, String result) {
		this(window);
		resultLabel.setText(result);
	}
	
	
	private void formatLabel() {
		resultLabel.setFont(new Font("Tempus Sans ITC", Font.BOLD, 14));
		resultLabel.setBackground(Color.WHITE);
		resultLabel.setForeground(Color.black);
		resultLabel.setSize(panelSize);
		//resultLabel.setLocation(0, 0);
	}

	@Override
	public void run() {
		resultLabel.setVisible(true);
		setVisible(true);
		dialog.setVisible(true);
		frameLocation = new Point(window.getParentComponent().getLocationOnScreen());
		dialog.setLocation(frameLocation.x, frameLocation.y - panelSize.height);
		window.setBoxFocus();
		dialog.transferFocus();
		try {
			Thread.sleep(2000);
			dialog.dispose();
		} catch (InterruptedException e) {

		} finally {
			dialog.dispose();
		}
	}

	public void setText(String result) {
		resultLabel.setText(result);
	}

}
